package com.gonsin.gview.model.dynamic.form;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@ApiModel("标签")
@AllArgsConstructor
@NoArgsConstructor
public class DynamicTag extends DynamicFormItem {

    @ApiModelProperty("selector表示下拉框，还有check_box\\file\\radio\\rich_text\\text_input\\tree_check_box\\tree_selector")
    private final String itemType = "tag";

    @ApiModelProperty("是否必选")
    private boolean required = true;

    @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
    private String keyName;

    @ApiModelProperty("显示的名字")
    private String name;

    @ApiModelProperty("提示语")
    private String placeholder;

    @ApiModelProperty("根据情况显示")
    private String showIf = "1";

    @ApiModelProperty("根据情况禁用")
    private String disableIf = "0";

    @ApiModelProperty("当单个表单项被修改时，触发对应的action事件")
    private String onChangeAction;

    public static DynamicTagBuilder builder() {
        return new DynamicTagBuilder();
    }


    public static final class DynamicTagBuilder {
        @ApiModelProperty("是否必选")
        private boolean required = true;

        @ApiModelProperty("查询或者提交表单时，表示  ${keyName}=value")
        private String keyName;

        @ApiModelProperty("显示的名字")
        private String name;

        @ApiModelProperty("提示语")
        private String placeholder;

        @ApiModelProperty("根据情况显示")
        private String showIf = "1";

        @ApiModelProperty("根据情况禁用")
        private String disableIf = "0";

        @ApiModelProperty("当单个表单项被修改时，触发对应的action事件")
        private String onChangeAction;

        private DynamicTagBuilder() {
        }

        public DynamicTagBuilder required(boolean required) {
            this.required = required;
            return this;
        }

        public DynamicTagBuilder keyName(String keyName) {
            this.keyName = keyName;
            return this;
        }

        public DynamicTagBuilder name(String name) {
            this.name = name;
            return this;
        }

        public DynamicTagBuilder placeholder(String placeholder) {
            this.placeholder = placeholder;
            return this;
        }

        public DynamicTagBuilder showIf(String showIf) {
            this.showIf = showIf;
            return this;
        }

        public DynamicTagBuilder disableIf(String disableIf) {
            this.disableIf = disableIf;
            return this;
        }

        public DynamicTagBuilder onChangeAction(String onChangeAction) {
            this.onChangeAction = onChangeAction;
            return this;
        }

        public DynamicTag build() {
            DynamicTag dynamicTag = new DynamicTag();
            dynamicTag.setRequired(required);
            dynamicTag.setKeyName(keyName);
            dynamicTag.setName(name);
            dynamicTag.setPlaceholder(placeholder);
            dynamicTag.setShowIf(showIf);
            dynamicTag.setDisableIf(disableIf);
            dynamicTag.setOnChangeAction(onChangeAction);
            return dynamicTag;
        }
    }
}
